// 配置路由的文件
import Vue from "vue";
import VueRouter from "vue-router";
import Home from "@/views/home.vue"; //路径别名，直接找到src
import Job from "@/views/job.vue";
import store from "@/store"; //此处的store等同于组件中的this.$store
Vue.use(VueRouter);

//创建路由对象
const router = new VueRouter({
  // mode:'history',  //启用history模式
  routes: [
    {
      path: "/",
      component: () => import("@/views/contractSign copy 2.vue"),
    },
    {
      path: "/vuex/test",
      component: () => import("@/views/vmodel.vue"),
    },
    {
      path: "/sign",
      component: () => import("@/views/contractSign.vue"),
    },
    {
      path: "/signtwo",
      component: () => import("@/views/contractSign copy 3.vue"),
    },
    {
      path: "/signa",
      component: () => import("@/views/contractSign copy 2.vue"),
    }
  ],
});

// 全局前置守卫
router.beforeEach((to, from, next) => {
  console.log(to, from);
  // next();
  let blackList = ["/mine"];
  if (blackList.includes(to.path)) {
    // 用户登录状态
    let { userInfo } = store.state.user;
    console.log(userInfo);
    if (userInfo) {
      next(); //已登录
    } else {
      store.commit("user/memoMut", to.path);
      next("/login"); //未登录
    }
  } else {
    next(); //不需要拦截的路由
  }
});

export default router;
